package com.woniuxy.project.campus.canteenOrder.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.woniuxy.project.campus.AccountOpenFeign;
import com.woniuxy.project.campus.CenteenCilnt;
import com.woniuxy.project.campus.TechnicalCilnt;
import com.woniuxy.project.campus.account.model.form.*;
import com.woniuxy.project.campus.canteenModelform.*;
import com.woniuxy.project.campus.canteenModelform.ProductListForm;
import com.woniuxy.project.campus.canteenOrder.dto.OrderInfoDto;
import com.woniuxy.project.campus.canteenOrder.dto.ProList;
import com.woniuxy.project.campus.canteenOrder.dto.SelectOrderByStateDto;
import com.woniuxy.project.campus.canteenOrder.mapper.OrderLogTableMapper;
import com.woniuxy.project.campus.canteenOrder.mapper.TakeoutOrdersMapper;
import com.woniuxy.project.campus.canteenOrder.model.OrderInfo;
import com.woniuxy.project.campus.canteenOrder.mapper.OrderInfoMapper;
import com.woniuxy.project.campus.canteenOrder.model.OrderLogTable;
import com.woniuxy.project.campus.canteenOrder.model.TakeoutOrders;
import com.woniuxy.project.campus.canteenOrder.service.OrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.woniuxy.project.campus.util.Result;
import com.woniuxy.project.campus.util.StaticData;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 猫将军
 * @since 2025年02月17日
 */
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Resource
    private OrderInfoMapper orderInfoMapper;
    @Resource
    private RedissonClient redissonClient;
    @Resource
    private CenteenCilnt centeenCilnt;
    @Resource
    private TakeoutOrdersMapper takeoutOrdersMapper;
    @Resource
    private OrderLogTableMapper orderLogTableMapper;
    @Resource
    private AccountOpenFeign accountOpenFeign;
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private AlipayClient alipayClient;
    @Resource
    private TechnicalCilnt technicalCilnt;

    @Override
    public OrderInfoDto addOrder(Integer accountId, AddOrderForm param) throws Exception {
        ArrayList<Map<Object, Object>> shoppings = new ArrayList<>();
        RLock[] lock = new RLock[param.getProductIds().size()];
        for (int i = 0; i < param.getProductIds().size(); i++) {
            RLock fairLock = redissonClient.getFairLock(RedisKey.lockProductId( param.getProductIds().get(i)));
            lock[i] = fairLock;
        }

        RLock lockAll = redissonClient.getMultiLock(lock);
        try{

        //检查商品是否存在
        for (Integer productId : param.getProductIds()) {
            Result result = centeenCilnt.queryProductDetailById(productId);
            ProductListForm bean = BeanUtil.toBean(result.getData(), ProductListForm.class);
            if (bean == null || bean.getProductStatus().equals(StaticData.FOOD_STATUS_DOWN)) {
                throw new RuntimeException("商品不存在或状态异常");
            }
        }
        Collections.sort(param.getProductIds());

        //从redis中取出购物车
        for (Integer productId : param.getProductIds()) {
         StringKAndVForm stringKAndVForm = new StringKAndVForm();
            stringKAndVForm.setKey(RedisKey.userCart(accountId));
            stringKAndVForm.setValue(String.valueOf(productId));
            Result score = accountOpenFeign.score(stringKAndVForm);


            if (score.getData() == null) {
                throw new RuntimeException("购物车中没有该商品");
            } else {
                // 从购物车详情中取出数量，比对数据库中的数量
                Result hashMapAll = accountOpenFeign.getHashMapAll(RedisKey.userCartOrder(accountId, productId));
                Object data = hashMapAll.getData();
                Map<Object, Object> map = JSONUtil.toBean(JSONUtil.toJsonStr(data), Map.class);
                map.put("score", score.getData());
                shoppings.add(map);
            }
        }
            BigDecimal totalPrice = new BigDecimal(0);
            ProductListForm bean = null;
            for (int i = 0; i < shoppings.size(); i++) {
                Integer productId = Integer.parseInt(shoppings.get(i).get("productId").toString());
                Integer num = Integer.parseInt(shoppings.get(i).get("number").toString());
                Result result = centeenCilnt.queryProductDetailById(productId);
                bean = BeanUtil.toBean(result.getData(), ProductListForm.class);
                if (bean.getDiscountPrice() == null) {
                    totalPrice = totalPrice.add(bean.getPrice().multiply(BigDecimal.valueOf(num)));
                } else {
                    totalPrice = bean.getPrice().multiply(BigDecimal.valueOf(num).multiply(bean.getDiscountPrice()));

                }
            }
           //生成订单信息
            TakeoutOrders takeoutOrders = new TakeoutOrders();
            String orderNum1 = new Snowflake(1, 1).nextIdStr();
            String randomSuffix = String.format("%03d", new Random().nextInt(1000)); // 生成3位随机数
            String orderNum = orderNum1.substring(0, 7) + randomSuffix; // 将7位 Snowflake ID 加上3位随机数

            takeoutOrders.setOrderNumber(orderNum);
            takeoutOrders.setShopId(bean.getShopId());
            //收货人
            takeoutOrders.setAccountName(param.getAccountName());
            //订单创建时间
            takeoutOrders.setCreationTime(LocalDateTime.now());
            //订单支付状态
            takeoutOrders.setPaymentStatus(StaticData.ORDER_PAY_STATUS_WAIT);
            //订单状态
            takeoutOrders.setCurrentState(StaticData.ORDER_STATUS_WAIT_PAY);
            //订单总价
            takeoutOrders.setTotalAmount(totalPrice);
            //收货地址
            takeoutOrders.setAddressName(param.getAddress());
            //收货人电话
            takeoutOrders.setAccountPhone(param.getPhone());
            //配送方式
            takeoutOrders.setDeliveryMethod(StaticData.ORDER_DELIVERY_DELIVERY);
            //用户备注
            takeoutOrders.setUserRemarks(param.getRemark());
            takeoutOrders.setAccountId(accountId);
            takeoutOrdersMapper.insert(takeoutOrders);

            ArrayList<Map<Object, Object>> detailList = new ArrayList<>();
            try{
                for(Map<Object, Object> map:shoppings){
                    Integer productId = Integer.parseInt(map.get("productId").toString());
                    Integer number = Integer.parseInt(map.get("number").toString());

                    System.out.println("此次购买的商品数量----------------------------------"+number);
                    OrderInfo orderInfo = new OrderInfo();
                    orderInfo.setOrderNum(orderNum);
                    //购买的数量
                    System.out.println("购买的数量"+number);
                    orderInfo.setQuantityOfGoods(number);
                    //商品id
                    orderInfo.setProductId(productId);
                    //商品金额
                    orderInfo.setAmountOfMoney(totalPrice);
                    AddAddressForm addAddressForm = new AddAddressForm();
                    addAddressForm.setUserName(param.getAccountName());
                    addAddressForm.setPhone(param.getPhone());
                    addAddressForm.setAddressName(param.getAddress());
                    Result addressId = centeenCilnt.getAddressId(addAddressForm);
                    orderInfo.setQuantityName(addressId.getData().toString());
                    //插入
                    orderInfoMapper.insert(orderInfo);
                    accountOpenFeign.delete(RedisKey.userCartOrder(accountId, productId));
                    StringKAndVForm stringKAndVForm = new StringKAndVForm();
                    stringKAndVForm.setKey(RedisKey.userCart(accountId));
                    stringKAndVForm.setValue(String.valueOf(productId));
                    accountOpenFeign.zrem(stringKAndVForm);
                    //记录详情
                    detailList.add(map);
                }
                //记录订单日志
                OrderLogTable orderLogTable = new OrderLogTable();
                orderLogTable.setOrderNumber(orderNum);
                orderLogTable.setCreationTime(LocalDateTime.now());
                //订单状态
                orderLogTable.setCurrentStatus(StaticData.ORDER_LOG_WAIT_PAY);
                //下单用户
                orderLogTable.setAccountId(accountId);
                //店铺id
                orderLogTable.setShopId(bean.getShopId());
                //商品id
                orderLogTable.setProductId(bean.getId());
                orderLogTableMapper.insert(orderLogTable);
                OrderInfoDto orderInfoDto = new OrderInfoDto();
                orderInfoDto.setOrderNumber(orderNum);
                orderInfoDto.setAddress(param.getAddress());
                orderInfoDto.setPhone(param.getPhone());
                orderInfoDto.setTotalPrice(totalPrice);
                orderInfoDto.setOrderTime(LocalDateTime.now());

                rabbitTemplate.convertAndSend("Order_Delete", orderNum);
                return orderInfoDto;
            }catch (Exception e){
                //如果插入订单详情失败 则需要进行补偿删除
                for (Map<Object, Object> map : detailList){
                    //商品id
                    String productId =map.get("productId").toString();
                    //取出数量

                    double scores = Double.parseDouble(map.get("score").toString());
                    Set1Foram set1Foram = new Set1Foram();
                    set1Foram.setKey(RedisKey.userCart(accountId));
                    set1Foram.setValue(productId);
                    set1Foram.setTimeout( (long) scores);
                    accountOpenFeign.zadd( set1Foram);
                    //移除Hash
                    map.remove("score");
                    //？？？？？？？？
                    SaveHashMapForm saveHashMapForm = new SaveHashMapForm();
                    saveHashMapForm.setKey(RedisKey.userCartOrder(accountId, Integer.parseInt(productId)));
                    saveHashMapForm.setMap(map);
                    accountOpenFeign.saveHashMap(saveHashMapForm);
                }
                throw  e;
            }
        }finally{
            lockAll.unlock();
        }
    }

   @Override
 public String payOrder(Integer accountId, String orderNum) throws Exception {
    QueryWrapper<TakeoutOrders> queryWrapper = new QueryWrapper<>();
    String[] orderNums = orderNum.split(",");
    BigDecimal bigDecimal = new BigDecimal(0);
    LocalDateTime creationTime = null;

    // 遍历订单号，逐个查询订单信息
    for (String singleOrderNum : orderNums) {
        queryWrapper.clear();
        queryWrapper.eq("order_number", singleOrderNum);
        List<TakeoutOrders> takeoutOrders = takeoutOrdersMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(takeoutOrders)) {
            throw new RuntimeException("订单不存在");
        }

        for (TakeoutOrders takeoutOrder : takeoutOrders) {
            if (!takeoutOrder.getCurrentState().equals(StaticData.ORDER_STATUS_WAIT_PAY)) {
                throw new RuntimeException("订单状态异常");
            }
            bigDecimal = bigDecimal.add(takeoutOrder.getTotalAmount());
            // 取最早的创建时间
            if (creationTime == null || takeoutOrder.getCreationTime().isBefore(creationTime)) {
                creationTime = takeoutOrder.getCreationTime();
            }
            if(takeoutOrders!= null) {
                //记录今日营业额
                Set1Foram set1Foram = new Set1Foram();
                set1Foram.setKey(RedisKey.userOrderMoney(String.valueOf(takeoutOrder.getShopId())));
                set1Foram.setValue(takeoutOrder.getOrderNumber());
                set1Foram.setTimeout(new Date().getTime());
                accountOpenFeign.zadd(set1Foram);

                QueryWrapper<OrderInfo> queryWrapper1 = new QueryWrapper<>();
                queryWrapper1.eq("order_num", takeoutOrder.getOrderNumber());
                OrderInfo orderInfo = orderInfoMapper.selectOne(queryWrapper1);
                HashMap<String, String> map = new HashMap<>();
                map.put("shopId", String.valueOf(takeoutOrder.getShopId()));
                map.put("number", String.valueOf(orderInfo.getQuantityOfGoods()));
                map.put("productId", String.valueOf(orderInfo.getProductId()));
                map.put("money", bigDecimal.toString());
                SetHashMapForm setHashMapForm = new SetHashMapForm();
                setHashMapForm.setKey(RedisKey.orderSettlementKey(takeoutOrder.getShopId().toString(),takeoutOrder.getOrderNumber()));
                setHashMapForm.setMap(map);
                accountOpenFeign.setHashMap(setHashMapForm);
            }
        }
    }
       //实例化网页支付请求对象
       AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
       //创建键值对设置请求参数
       Map<String, Object> params = new HashMap<>();
       //设置订单号
       params.put("out_trade_no", orderNum);
       //设置总金额
       params.put("total_amount", bigDecimal);
       //设置商户名字
       params.put("subject", "想你了牢大");
       //设置付款说明
       params.put("body", "吃我一肘击");

       params.put("product_code", "FAST_INSTANT_TRADE_PAY");
       //设置剩余有效时间
       LocalDateTime now = creationTime.plusMinutes(15);
       //设置格式
       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
       params.put("time_expire", now.format(formatter));
       //将键值对参数转为json字符串
       String jsonStr = JSONUtil.toJsonStr(params);
       request.setBizContent(jsonStr);
       //设置同步回调地址/=p
       request.setReturnUrl("http://isgua2.natappfree.cc/#/OrderingAMeal");
       //http://4j64s7.natappfree.cc/#/PendingPaymentPage
//       http://xd9f7w.natappfree.cc/#/login
       //设置异步回调地址
       request.setNotifyUrl("http://87yusn.natappfree.cc/canteenOrder/orderInfo/payCallback");
       //发起支付请求
       AlipayTradePagePayResponse response = alipayClient.pageExecute(request);

        paySuccess(orderNum);


       //判断是否成功
       if (response.isSuccess()){
           //成功返回支付页面地址
           return response.getBody();
       }
       throw new RuntimeException("发起支付失败");
}

// 抽取支付参数构造逻辑
//private Map<String, Object> buildPayParams(String orderNum, BigDecimal totalAmount, LocalDateTime creationTime) {
//    Map<String, Object> params = new HashMap<>();
//    params.put("out_trade_no", orderNum);
//    params.put("total_amount", totalAmount);
//    params.put("subject", "蜗牛收银台");
//    params.put("body", "吃我一肘击");
//    params.put("product_code", "FAST_INSTANT_TRADE_PAY");
//    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//    params.put("time_expire", creationTime.plusMinutes(15).format(formatter));
//    return params;
//}


    @Override
    public void updateOrderState(String outTradeNo, LocalDateTime localDateTime) throws Exception {
        //通过订单号查询订单
        TakeoutOrders takeoutOrders = takeoutOrdersMapper.selectById(outTradeNo);
        if (takeoutOrders == null) {
            throw new RuntimeException("订单不存在");
        }
//        RLock fairLock = redissonClient.getFairLock(RedisKey.lockProductId(Integer.valueOf(outTradeNo)));
        if (takeoutOrders.getPaymentStatus().equals(StaticData.ORDER_PAY_STATUS_WAIT)&&takeoutOrders.getCurrentState().equals(StaticData.ORDER_STATUS_WAIT_PAY)) {
            //更新状态
            takeoutOrders.setPaymentStatus(StaticData.ORDER_PAY_STATUS_PAID);
            takeoutOrders.setCurrentState(StaticData.ORDER_STATUS_PAID);
            //支付时间
            takeoutOrders.setPaymentTime(localDateTime);
            //更新订单
            takeoutOrdersMapper.updateById(takeoutOrders);
            //给商家发送消息
            Result result1 = centeenCilnt.queryProductDetailByShopId(takeoutOrders.getShopId());
            Integer bossId = (Integer) result1.getData();
            technicalCilnt.sendCode(bossId.toString(), "您有新的订单待接单");
        }

    }

@Override
public List<SelectOrderByStateDto> selectOrderByState(Integer accountId) {
    //先查用户有几个 订单
    QueryWrapper<OrderLogTable> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("account_id", accountId)
            .eq("current_status", StaticData.ORDER_LOG_WAIT_PAY);
    List<OrderLogTable> orderLogTables = orderLogTableMapper.selectList(queryWrapper);
    queryWrapper.clear();
    if (orderLogTables == null || orderLogTables.isEmpty()) {
        return Collections.emptyList();
    }
    List<SelectOrderByStateDto> selectOrderByStateDtos = new ArrayList<>();
    for (OrderLogTable orderTable : orderLogTables) {
        QueryWrapper<OrderInfo> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("order_num", orderTable.getOrderNumber());
        List<OrderInfo> orderInfos = orderInfoMapper.selectList(queryWrapper1);
        queryWrapper1.clear();
        if (orderInfos == null || orderInfos.isEmpty()) {
            continue;
        }
        SelectOrderByStateDto selectOrderByStateDto = new SelectOrderByStateDto();
        BigDecimal bigDecimal = new BigDecimal(0);
        List<ProList> proLists = new ArrayList<>();
        Result result1 = null;
        for (OrderInfo orderInfo : orderInfos) {
            ProList proList = new ProList();
            Result result = centeenCilnt.queryProductDetailById(orderInfo.getProductId());
            ProductListForm bean = BeanUtil.toBean(result.getData(), ProductListForm.class);
            proList.setProductName(bean.getProductName());
            proList.setProductPrice(orderInfo.getAmountOfMoney());
            bigDecimal = bigDecimal.add(orderInfo.getAmountOfMoney());
            proList.setProductNum(orderInfo.getQuantityOfGoods());
            proList.setProductImg(bean.getPicture());
            proLists.add(proList);
        }
        // 查地址信息，这里假设每个订单只有一个地址信息
        if (!orderInfos.isEmpty()) {
            result1 = centeenCilnt.getAddressByAddressId(Integer.valueOf(orderInfos.get(0).getQuantityName()));
        }
        selectOrderByStateDto.setOrderNo(orderTable.getOrderNumber());
        selectOrderByStateDto.setCreateTime(orderTable.getCreationTime());
        selectOrderByStateDto.setState(orderTable.getCurrentStatus());
        selectOrderByStateDto.setTotalPrice(bigDecimal);
        selectOrderByStateDto.setProList(proLists);
        if (result1 != null) {
            AddAddressForm bean = BeanUtil.toBean(result1.getData(), AddAddressForm.class);
            selectOrderByStateDto.setUserName(bean.getUserName());
            selectOrderByStateDto.setUserAddress(bean.getAddressName());
            selectOrderByStateDto.setUserPhone(bean.getPhone());
        }
        selectOrderByStateDtos.add(selectOrderByStateDto);
    }
    return selectOrderByStateDtos;
}

    @Override
    public String getTodayTotalIncome(Integer accountId) throws Exception {
        Result shopIdByAccessId = centeenCilnt.getShopIdByAccessId(accountId);
        Integer shopId = (Integer) shopIdByAccessId.getData();
        Result result = accountOpenFeign.hasKey(RedisKey.userOrderMoney(String.valueOf(shopId)));
        BigDecimal bigDecimal = new BigDecimal(0);
        if((boolean)result.getData()){
            Result zSetMembers = accountOpenFeign.getZSetMembers(RedisKey.userOrderMoney(String.valueOf(shopId)));
            Object data = zSetMembers.getData();
            ArrayList<String> zrevrange = (ArrayList<String>) data;
            for(String num:zrevrange){
                Result<HashMap<Object, Object>> hashMapAll = accountOpenFeign.getHashMapAll(RedisKey.orderSettlementKey(shopId.toString(), num));
                HashMap<Object, Object> map = hashMapAll.getData();
                for (Map.Entry<Object, Object> entry : map.entrySet()) {
                    if ("money".equals(entry.getKey())) {
                        String money = entry.getValue().toString();
                        bigDecimal = bigDecimal.add(new BigDecimal(money));
                    }
                }
            }
        }

        return bigDecimal.toString();
    }

    @Override
    public List<SelectOrderByStateForm> selectOrderByState1(Integer accountId) {
        Result shopIdByAccessId = centeenCilnt.getShopIdByAccessId(accountId);
        Integer shopId = (Integer) shopIdByAccessId.getData();
        QueryWrapper<TakeoutOrders> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("shop_id", shopId)
                .eq("current_state", StaticData.ORDER_STATUS_PAID)
                .eq("payment_status", StaticData.ORDER_PAY_STATUS_PAID);

        List<TakeoutOrders> takeoutOrders = takeoutOrdersMapper.selectList(queryWrapper);
        queryWrapper.clear();
        if (takeoutOrders == null || takeoutOrders.isEmpty()) {
            throw new RuntimeException("暂无待处理订单");
        }
        List<SelectOrderByStateForm> selectOrderByStateForms = new ArrayList<>();
        SelectOrderByStateForm selectOrderByStateForm = new SelectOrderByStateForm();
        for (TakeoutOrders takeoutOrder : takeoutOrders){
            QueryWrapper<OrderInfo> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("order_num", takeoutOrder.getOrderNumber());
            OrderInfo orderInfos = orderInfoMapper.selectOne(queryWrapper1);
            //传地址id查询地址
            Result addressByAddressId = centeenCilnt.getAddressByAddressId(Integer.valueOf(orderInfos.getQuantityName()));
            AddressForm bean = BeanUtil.toBean(addressByAddressId.getData(), AddressForm.class);
            selectOrderByStateForm.setOrderNum(takeoutOrder.getOrderNumber());
            selectOrderByStateForm.setOrderState(takeoutOrder.getCurrentState()==2?"已支付":"未知状态");
            //LocalDateTime转String
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            // 转换为字符串
            String formattedDateTime = takeoutOrder.getPaymentTime().format(formatter);
            selectOrderByStateForm.setOrderTime(formattedDateTime);
            //通过商品id查询商品名字
            Result result = centeenCilnt.queryProductNameId(orderInfos.getProductId());
            selectOrderByStateForm.setProductName((String) result.getData());
            selectOrderByStateForm.setProductNum(String.valueOf(orderInfos.getQuantityOfGoods()));
            //收货人信息
            selectOrderByStateForm.setUserName(bean.getUserName());
            selectOrderByStateForm.setUserAddress(bean.getAddressName());
            selectOrderByStateForm.setUserPhone(bean.getPhone());
            selectOrderByStateForms.add(selectOrderByStateForm);
        }


        return selectOrderByStateForms;
    }


    //支付成功
    public void paySuccess(String orderNum) throws Exception {
        QueryWrapper<TakeoutOrders> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_number", orderNum);
        TakeoutOrders takeoutOrders = takeoutOrdersMapper.selectOne(queryWrapper);
        //订单状态改为已支付
        takeoutOrders.setPaymentStatus(StaticData.ORDER_PAY_STATUS_PAID);
        //订单当前状态
        takeoutOrders.setCurrentState(StaticData.ORDER_STATUS_PAID);
        //支付方式
        takeoutOrders.setPaymentMethod(StaticData.ORDER_PAY_TYPE_ALIPAY);
        //支付时间
        takeoutOrders.setPaymentTime(LocalDateTime.now());
        //修改订单信息
        //先删除之前的
        orderLogTableMapper.delete(new QueryWrapper<OrderLogTable>().eq("order_number", orderNum));

        takeoutOrdersMapper.updateById(takeoutOrders);
        //新增订单日志
        OrderLogTable orderLogTable = new OrderLogTable();
        orderLogTable.setOrderNumber(orderNum);
        //订单状态
        orderLogTable.setCurrentStatus(StaticData.ORDER_LOG_PAID);
        //时间
        orderLogTable.setCreationTime(LocalDateTime.now());
        //
        orderLogTable.setAccountId(takeoutOrders.getAccountId());
        orderLogTable.setShopId(takeoutOrders.getShopId());
        orderLogTable.setProductId(takeoutOrders.getId());
        orderLogTableMapper.insert(orderLogTable);
        //通知商家接单
        Result result1 = centeenCilnt.queryProductDetailByShopId(takeoutOrders.getShopId());
        Integer bossId = (Integer) result1.getData();
        technicalCilnt.sendCode(bossId.toString(), "您有新的订单待接单，请及时处理");
    }

}
